﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class PriceStructure
    {
        public static void insert(PriceStructureEntity priceStructure)
        {
            DbHelper.ExecuteNonQuery("p_PriceStructure_insert",
              priceStructure.CompanyId,
              priceStructure.ProductId,
              priceStructure.CategoryId,
              priceStructure.AutoPercent
               );
        }

        public static void insertByProduct(PriceStructureEntity priceStructure)
        {
            DbHelper.ExecuteNonQuery("p_PriceStructure_insertByProduct",            
              priceStructure.ProductId,
              priceStructure.CategoryId
             // priceStructure.AutoPercent
               );
        }

        public static void updateByProduct(PriceStructureEntity priceStructure)
        {
            DbHelper.ExecuteNonQuery("p_PriceStructure_updateByProduct",             
              priceStructure.CompanyId,
              priceStructure.ProductId,
              priceStructure.CategoryId,
              priceStructure.AutoPercent
               );
        }


        public static void deleteByCompany(int companyId)
        {
            DbHelper.ExecuteNonQuery("p_PriceStructure_deleteByCompany",
                companyId);
        }

        public static void Init(int adminId,int companyId, string categoryAutoPercentMap)
        {
            DbHelper.ExecuteNonQuery("[dbo].[p_PriceStructure_Init]",adminId,companyId, categoryAutoPercentMap);
        }

        public static void update(int companyId, int productId, decimal productAutoAdd, decimal autoPercent,int adminId)
        {
            DbHelper.ExecuteNonQuery("[dbo].[p_PriceStructure_updateByCompanyIdAndProductId]",companyId,productId,productAutoAdd,autoPercent,adminId);
        }

        public static DataTable getProductAutoAddByProductNameOrProductNo(string Rn, string whereClause,bool enableLike)
        {
            return DbHelper.ExecuteDataTable("[dbo].[p_PriceStructure_getProductAutoAddByProductNameOrProductNo]", Rn, whereClause,enableLike);
        }

        public static void updateProductAutoAddBlock(int adminId, int productId,decimal oldProductAutoadd,decimal productAutoadd, bool isApplyAll)
        {
            DbHelper.ExecuteNonQuery("[dbo].[p_PriceStructure_updateProductAutoAddBlock]", adminId, productId, oldProductAutoadd, productAutoadd, isApplyAll);
        }

        public static void InsertProductAutoAdd(string nature, int companyId, int adminId)
        {
            DbHelper.ExecuteNonQuery("[dbo].[p_priceStructureByinserting]", nature, companyId, adminId);
        }

        //根据采购档次以及商品ID修改系统加价体系
        public static void updateByProductIdAndBN(string bn, int productId, decimal sysAutoAdd,int adminId)
        {
            DbHelper.ExecuteNonQuery("[dbo].[p_PriceStructure_updateByProductIdAndBN]", bn, productId, sysAutoAdd, adminId);
        }
    }
}
